﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MarchEstate.Manager.BusinesEntity;
using MarchEstate.Manager.Dao.Init;

namespace MarchEstate.Manager.ObjectModel.Init
{
    public class ServiceItem : AbstractServiceItem
    {

        private ServiceItemDao itemDao = null;

        public ServiceItem()
        {
        }

        public override void InitDao()
        {
            base.InitDao();
            itemDao = NewDao<ServiceItemDao>();
        }

        public override bool Save(string type)
        {
            if (type == "add")
            {
                if (itemDao.Existserviceitemcode(Code))
                {
                    throw new Exception("输入的代码已存在，请重新输入！");
                }
                return itemDao.AddServiceItem(this);
            }
            else if (type == "alter")
            {
                return itemDao.UpdateServiceItem(this);
            }
            return true;
        }

        public override bool Delete(int _code)
        {
            throw new NotImplementedException();
        }

        public override AbstractServiceItem GetServiceItem(string _code)
        {
            return itemDao.GetServiceItem(_code);
        }

        public override List<AbstractServiceItem> GetServiceItemList(string _statCode, string _type)
        {
            return itemDao.GetServiceItemList(_statCode,_type);
        }

        public override bool SaveStatItem(string type,string code, string statname)
        {
            if (type == "add")
            {
                if (itemDao.ExistStatitemcode(code))
                {
                    throw new Exception("输入的代码已存在，请重新输入！");
                }
                return itemDao.AddStatItem(code, statname);
            }
            else if (type == "alter")
            {
                return itemDao.UpdateStatItem(code, statname);
            }
            return true;
        }

        public override System.Data.DataTable GetStatItemData()
        {
            return itemDao.GetStatItemData();
        }

        public override bool DeleteStatItem(string code)
        {
            return itemDao.DeleteStatItem(code);
        }
    }
}
